package com.share.web.action.site.navigation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;
import com.share.bean.site.SiteNavi;
import com.share.service.site.navigation.SiteNaviManager;

@Component
@Scope("prototype")
public class SiteNaviAction extends ActionSupport implements ServletRequestAware{

	private static final long serialVersionUID = 1L;

	@Resource
	private SiteNaviManager snm;

	private SiteNavi sn;

	private Object[] ids;
	
	public Object[] getIds() {
		return ids;
	}

	public void setIds(Object[] ids) {
		this.ids = ids;
	}

	private HttpServletRequest request ;
	
	private int sniId ;

	public String addSiteNavi() throws Exception {
		sniId = sn.getSiteNaviItem().getId() ;
		int ret = this.snm.saveSiteNaviManager(sn);
		if (ret == 1) {
			return SUCCESS;
		} else {
			return ERROR;
		}
	}

	public String deleteSiteNavi() throws Exception {
		sniId = sn.getId() ;
		int ret = this.snm.deleteSiteNaviManager(ids);

		if (ret == 1) {
			return SUCCESS;
		} else {
			return ERROR;
		}
	}

	public String queryAllSiteNavi() throws Exception {

		request.setAttribute("querNaviAll",this.snm.queryAllSiteNaviManager()) ;

		return "queryAllNavi";
	}

	public String queryByIdSiteNavi() throws Exception {

		request.setAttribute("snvo",this.snm.queryByIdSiteNaviManager(sn.getId()));

		return "queryById";
	}
	
	public String updateSiteNavi() throws Exception {
		sniId = sn.getSiteNaviItem().getId() ;
		this.snm.updateSiteNaviManager(sn) ;

		return SUCCESS;
	}


	public SiteNavi getSn() {
		return sn;
	}

	public int getSniId() {
		return sniId;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request ;
	}

	public void setSn(SiteNavi sn) {
		this.sn = sn;
	}
	
	public void setSniId(int sniId) {
		this.sniId = sniId;
	}

	public void setSnm(SiteNaviManager snm) {
		this.snm = snm;
	}

}
